import java.io.File;
import java.util.Scanner;
import java.io.FileNotFoundException;
import java.util.NoSuchElementException;

/**
 * 
 * Contains a list of Planet objects, along with a method to read them in from a file.
 *
 */
public class PlanetList extends BaphiList  {
	
	/**
	 * Contains a list of Planet objects, along with a method to read them in from a file.
	 * @param fileName
	 * @param numPlayers
	 * @throws FileNotFoundException
	 * @throws NoSuchElementException
	 */
	public PlanetList(String fileName, int numPlayers) throws FileNotFoundException, NoSuchElementException
	{
		readPlanetsFromFile(fileName, numPlayers);
	}
	
	/**
	 * @return Planet
	 */
	public Planet get(int idx)
	{
		return (Planet) super.get(idx);
	}
	
	/**
	 * Reads Planets from the specified file path and populates the PlanetList
	 * @param playerFile
	 * @param numPlayers
	 * @throws FileNotFoundException
	 * @throws NoSuchElementException
	 */
	private void readPlanetsFromFile(String playerFile, int numPlayers) throws FileNotFoundException, NoSuchElementException
	{
		File file = new File(playerFile);
		Scanner scan;
		String name;
		int location;

		scan = new Scanner(file);
		scan.useDelimiter(",|\n");
		
		while(scan.hasNext())
		{	
			name = scan.next();
			location = scan.nextInt();
			
			this.add(new Planet(name, location, numPlayers));
		}
		
		scan.close();
	}
}

